package com.ziyun.erp.web.api.goods;

import com.ziyun.erp.modules.goods.entity.GoodsProductEntity;
import com.ziyun.erp.modules.goods.service.GoodsProductService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 产品表
 *
 * @author xueqz
 * @email
 * @date 2018-08-21 08:46:29
 */
@RestController
@RequestMapping("port/goods/goodsproduct")
public class GoodsProductControllerApi {
    @Autowired
    private GoodsProductService goodsProductService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsProductService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{productId}")
    public R info(@PathVariable("productId") Long productId){
        GoodsProductEntity goodsProduct = goodsProductService.selectById(productId);
        return R.ok().put("goodsProduct", goodsProduct);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody GoodsProductEntity goodsProduct){
        goodsProductService.insert(goodsProduct);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody GoodsProductEntity goodsProduct){
        ValidatorUtils.validateEntity(goodsProduct);
        goodsProductService.updateAllColumnById(goodsProduct);//全部更新
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] productIds){
        goodsProductService.deleteBatchIds(Arrays.asList(productIds));
        return R.ok();
    }

}
